package com.kiwi.util;

import java.security.MessageDigest;

/**
 * Created by gaolei on 2017/9/18.
 */
public class MD5Util
{
	private static final char[] HEX_DIGITS =
			new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

	public static String getMD5(String message) {
		String digest = message;

		try {
			MessageDigest e = MessageDigest.getInstance("MD5");
			e.reset();
			e.update(message.getBytes("UTF-8"));
			digest = toHexString2(e.digest());
		} catch (Exception var3) {
			var3.printStackTrace();
		}

		return digest.toLowerCase();
	}

	public static String toHexString2(byte[] b) {
		StringBuilder sb = new StringBuilder(b.length * 2);

		for (int i = 0; i < b.length; ++i) {
			sb.append(HEX_DIGITS[(b[i] & 240) >>> 4]);
			sb.append(HEX_DIGITS[b[i] & 15]);
		}
		return sb.toString();
	}
}
